/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/**
 * 财务管理APP充值金额查询
 *  */

import React, { useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ProForm, { ProFormText, ProFormTextArea } from '@ant-design/pro-form';
import type { ProFormInstance } from '@ant-design/pro-form';
import { Popconfirm, message, Button, Select, Form } from 'antd';
import { tmpUpdata } from '@/services/networkWx';
import styles from './tmpUpdata.less';

const Option = Select;
const NoticeVerify: React.FC = () => {
  const formRef = useRef<ProFormInstance>();

  const onSubmit = (values: any) => {
    const { prefix, id } = values;
    values.platform = prefix + id;
    delete values.prefix;
    delete values.id;
    tmpUpdata(values).then(({ code, msg }: any) => {
      if (code == 0) {
        message.success(msg);
        formRef.current?.resetFields();
      } else {
        message.error(msg);
      }
    });
  };

  const prefixSelector = (
    <Form.Item name='prefix' noStyle>
      <Select style={{ width: 130 }}>
        <Option value='wt_weixin_'>wt_weixin_</Option>
        <Option value='weixin_shop_'>weixin_shop_</Option>
      </Select>
    </Form.Item>
  );

  return (
    <PageContainer className={styles.tmpUpdata}>
      <ProForm
        formRef={formRef}
        onFinish={onSubmit}
        initialValues={{
          prefix: 'wt_weixin_',
        }}
        submitter={{
          render: (props) => {
            return [
              <Popconfirm title='是否确认发布' onConfirm={() => props.form?.submit?.()}>
                <Button size='large' style={{ padding: '0 20px', margin: 20 }} type='primary'>
                  确认发布
                </Button>
              </Popconfirm>,
            ];
          },
        }}
      >
        <ProFormText
          name='id'
          label='公众号平台id'
          rules={[{ required: true, message: '请输入公众号平台id' }]}
          placeholder='请输入公众号平台id'
          fieldProps={{
            addonBefore: prefixSelector,
          }}
        />
        <ProFormText
          name='name'
          label='公众号名称'
          rules={[{ required: true, message: '请输入公众号名称' }]}
          placeholder='请输入公众号名称'
        />
        <ProFormTextArea
          name='remark'
          label='备注内容'
          placeholder='请输入备注内容'
          rules={[{ required: true, message: '请输入备注内容' }]}
          fieldProps={{
            rows: 4,
            maxLength: 100,
          }}
        />
        <div style={{ color: 'orange' }}>
          注：请勿发布一些污秽、色情、诈骗的信息，避免账号被封。
        </div>
      </ProForm>
    </PageContainer>
  );
};

export default NoticeVerify;
